$(function () {
    findHomeData();
});

function findHomeData() {
    $.ajax({
        url: '/home',
        data: {},
        type: 'get',
        dataType: 'json',
        success: function (res) {
            console.log(res);
            setNewsModelList(res.newsModelList);

        }
    })
}

function setNewsModelList(data) {

    let html = '';
    data.forEach(function (elem, index) {
        html += '                            <div>\n' +
            '                                <div onclick="goToProductPage(' + elem.id + ')">' + elem.title + '</div>\n' +
            '                                <div>\n' +
            '                                   ' + elem.content + '\n' +
            '                                </div>\n' +
            '\n' +
            '                            </div>';
    });
    $("#news").html(html);
}

function goToProductPage(id) {
    sessionStorage.setItem("productId", id);

    window.location.href = '/html/front/productDetail.html';
}